$(document).ready(function(){
	$("body").delegate(".field", "click" ,function(e) {
		var title = $(this).data("title");
		var url=$(this).data("url") + "&v=" + Math.random();
		var icon=$(this).attr("icon");
		window.parent.OpenTab(title,url,icon,true);
    });	
	monConsoleField();
	
});
	function monConsoleField()
	{
		$.ajax({
			url:BASE_URL_BASE_URL_SYSTEM_INTERFACE_CRUD + '/statistics/forMonitorConsole' +'?v=' + Math.random(),
			dataType:'json',
			type:'get',
			contentType:"application/json",
			success:function(data){
				var html = '';
				var lines = ''
				var data = data.content;
				var len = data.length;
				var lines_len = Math.ceil(len / 3);
				$.ajax({
					url: BASE_URL_API + '/interfaceLastRunResults/runStatusOfField' +'?v=' + Math.random(),
					dataType:'json',
					type:'get',
					contentType:"application/json",
					success:function(dataSta){
						var lenSta = dataSta.fieldNamesOfFailed.length;
						if(lenSta === 0)
						{
							lenSta = 1;
						}
						var stat = '';
						var statTxt = ''
						for(var i = 0; i < len; i++)
						{
							stat = "normal";
							statTxt = "正常";
							for(var j = 0; j < lenSta; j++)
							{
								if(data[i].name === dataSta.fieldNamesOfFailed[j])
								{
									stat = "warn";
									statTxt = "异常";
								}
							}
							html += '<a href="javascript:void(0);" data-title="领域服务监控" data-url="../pages/InterfaceMonitoring/ServiceMonitoring/FieldServiceMonitor.html?id=' + data[i].id + '" class="field"><h4>' + data[i].name + '</h4><div class="field_li"><p class="fl">系统数：<span class="system_num">' + data[i].systemAmount + '</span></p><p class="fr ' + stat + '_tit">' + statTxt + '</p><div class="clearfix"></div><p class="fl">接口数：<span class="infterface_num">' + data[i].systemInterfaceAmount + '</span></p><p class="state ' + stat + ' fr"></p></div></a>';
						}
						$(".field_con").html(html);
						setTimeout(monConsoleField,30000);
					},
					error:function(){
						$.messager.alert("提示","<p>数据读取失败，请检查您的网络状态后，点击确认重新尝试连接！</p>","info", function()
						{
							window.location.href = window.location.href.replace(window.location.search,"") +'?v=' + Math.random() ;
						});
					}
				});
				for(var i = 0; i < lines_len; i++)
				{
					lines += '<div class="line"></div><div class="line"></div>';
				}
				lines += '<div class="clearfix"></div>';
				
				$(".lines").html(lines);
			},
			error:function(){
				$.messager.alert("提示","<p>数据读取失败，请检查您的网络状态后，点击确认重新尝试连接！</p>","info", function()
				{
					window.location.href = window.location.href.replace(window.location.search,"") +'?v=' + Math.random() ;
				});
			}
 		});
	}